import java.util.List;


class ListNode {
    public int val;
    public ListNode prev;//前驱
    public ListNode next;//后继

    public ListNode(int val) {
        this.val = val;
    }
    public ListNode() {
        ;
    }
    public static ListNode creatHead() {
        ListNode lhead = new ListNode();
        return lhead;
    }
    public static void insertFirst(ListNode head,int val) {
        if(head==null) {
            return;
        }
        ListNode temp = new ListNode(val);
        if(head.next!=null) {

            temp.next = head.next;
            temp.prev = head;
            head.next.prev = temp;
            head.next = temp;
        } else {
            head.next=temp;
            temp.prev=head;
            temp.next=null;
        }
    }
    public static void display(ListNode head) {
        ListNode cur = head.next;
        int i = 0;
        while(cur!=null) {
            System.out.println("第"+i+"个节点 值："+cur.val);
            cur=cur.next;
            i++;
        }
    }
}
public class MyLinkedList {
    public static void main(String[] args) {
        ListNode head = ListNode.creatHead();
        ListNode.insertFirst(head,2);
        ListNode.insertFirst(head,8);
        ListNode.display(head);
    }
}
